

/*for price using thousands separator */
export function fprice(s,n=2){
  s = parseFloat((s + "").replace(/[^\d\.-]/g, "")).toFixed(n) + "";    //n为小数点后保留小数位
  let l = s.split(".")[0].split("").reverse();
  let r = s.split(".")[1];
  let t = "";
  for(let i = 0; i < l.length; i ++ ){
     t += l[i] + ((i + 1) % 3 == 0 && (i + 1) != l.length ? "," : "");
  }
  return t.split("").reverse().join("") + "." + r;
}

const format =(arr,s)=>{
  return arr.map(i=>i<10?'0'+i:i).join(s)
}
export const dateFmt = (v)=>{
  const date = new Date(v)
  // 年月日
  const Y = date.getFullYear()
  const M = date.getMonth()+1
  const D = date.getDate()
  // 时分秒
  const h = date.getHours()
  const m = date.getMinutes()
  const s = date.getSeconds()

  const year = format([Y,M,D],'-')
  const time = format([h,m,s],':')

  return year +' '+time
}

export const firstUpperCase = (str)=>{
  return str.slice(0,1).toUpperCase()+str.slice(1)
}